package de.akabahn.ebd.fahrplan;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import de.akabahn.ebd.fahrplan.interfaces.FPLElementLoader;
import de.akabahn.ebd.fahrplan.structure.Bahnhof;

/**
 * Class for resolving useful elements, which may be needed during the
 * generation of a Fahrplan The current version supports the available Bahnhoefe
 * of the EBD.
 * 
 * @author Chris
 * @version 0.2
 * 
 */
public class FahrplanElements {

    /**
     * Hashmap containing a Bahnhof as value. The key is the short name of the
     * Bahnhof
     */
    private HashMap<String, Bahnhof> bahnhoefe;

    /**
     * Constructor
     * 
     * Only the storage variables are initialized
     */
    public FahrplanElements() {
	bahnhoefe = new HashMap<String, Bahnhof>();
    }

    /**
     * Method which initializes the data from a given loader. The loader has to
     * implement the FPLElementLoader interface
     * 
     * @param loader
     *            Loader, which loads the data from a defined source
     */
    public void initializeFrom(FPLElementLoader loader) {
	bahnhoefe = loader.loadBahnhoefe();
    }

    /**
     * Method for returning the loaded Bahnhoefe
     * 
     * @return Hashmap consisting of Strings as key (these correspond to the
     *         short names of the Bahnhof) and the Bahnhof datatypes as values
     */
    public HashMap<String, Bahnhof> getBahnhoefe() {
	return bahnhoefe;
    }

    /**
     * This method returns a list representation of all available Bahnhof
     * objects
     * 
     * @return List containing all Bahnhof objects
     */
    public List<Bahnhof> getBahnhoefeList() {
	List<Bahnhof> liste = new ArrayList<Bahnhof>();
	liste.addAll(bahnhoefe.values());
	return liste;
    }

}
